<route lang="json5" type="home">
{
  layout: 'default',
  style: {
    navigationBarTitleText: '首页',
  },
}
</route>

<template>
  <view class="">
    <my-search />
    <my-swiper />
    <my-nav />
    <myNews :list="state.article" />
    <wd-backtop :scrollTop="scrollTop"></wd-backtop>
    <mpPrivacyPopup />
  </view>
</template>

<script lang="ts" setup>
import mySearch from './components/my-search.vue'
import mySwiper from './components/my-swiper.vue'
import myNav from './components/my-nav.vue'
import myNews from './components/my-news.vue'
import mpPrivacyPopup from './components/mp-privacy-popup.vue'
import { indexUsingGet } from '@/api'
import { AjaxResultMapstring } from '@/api/types'

const scrollTop = ref<number>(0)
const state = reactive({
  pages: [],
  meta: [],
  article: [],
})

const getData = async () => {
  const res: AjaxResultMapstring = await indexUsingGet({})
  // state.pages = JSON.parse(data?.page?.data)
  // state.meta = JSON.parse(data?.page?.meta)
  state.article = res.data.article as []

  console.log('首页数据', state)

  // uni.setNavigationBarTitle({
  //   title: state.meta[0].content.title,
  // })
}

onPageScroll((event: any) => {
  scrollTop.value = event.scrollTop
  const top = uni.upx2px(100)
})

const onAgree = () => {
  console.log('用户同意隐私协议')
}

const onDisagree = () => {
  console.log('用户拒绝隐私协议')
  // 退出微信小程序
  uni.exitMiniProgram()
}

onLoad(() => {
  getData()
})
</script>

<style lang="scss" scoped>
//
</style>
